package view.quest
{
import core.Configuration;

import flash.display.MovieClip;
import flash.text.TextField;

import framework.core.AssetsManager;
import framework.core.FontLib;
import framework.core.popup.PopUpManager;
import framework.utils.TextUtil;
import framework.view.components.button.ButtonProxy;
import framework.view.components.graphics.Asset;

import quest.QuestManager;

import view.component.button.OKButtonProxy;

/**
 * QuestNPCDialogProxy
 * @author jliang
 * 
 */
public class QuestNPCDialogProxy extends QuestComponentProxyBase
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function QuestNPCDialogProxy()
	{
		super();
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	private var contentLabel:TextField;
	private var asset:Asset;
	private var okBtn:ButtonProxy;
	//==========================================================================
	//  Properties
	//==========================================================================
	public function set content(value:String):void
	{
		TextUtil.setText(contentLabel, value, FontLib.DESC_FONT_NAME);
	}
	
	public function get content():String
	{
		return contentLabel.text;
	}
	
	public function set picUrl(value:String):void
	{
		if (asset)
		{
			if (asset.parent)
			{
				asset.parent.removeChild(asset);
			}
			asset.dispose();
			asset = null;
		}
		asset = AssetsManager.loadAsset(Configuration.assetsPath + value);
		skin.iconHolder.addChild(asset);
	}
	
	public function get picUrl():String
	{
		return asset ? asset.url : "";
	}
	//==========================================================================
	//  Overridden methods: QuestComponentProxyBase
	//==========================================================================
	override public function parse(target:MovieClip):void
	{
		super.parse(target);
		
		contentLabel = skin.contentLabel;
		
		okBtn = new OKButtonProxy();
		okBtn.parse(skin.okBtn);
		okBtn.onClick = clickToOpenDetail;
	}
	
	override public function dispose():void
	{
		if (okBtn)
		{
			okBtn.dispose();
			okBtn = null;
		}
		if (asset)
		{
			if (asset.parent)
			{
				asset.parent.removeChild(asset);
			}
			asset.dispose();
			asset = null;
		}
		super.dispose();
	}
	
	protected function clickToOpenDetail():void
	{
		QuestManager.instance.viewQuestDetail(data);
		
		PopUpManager.close(skin.parent);
		
		uiComplete();
	}
}
}


